<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户信息</title>
<script src="../js/jquery-1.11.1.js"></script>
<script type="text/javascript">
//function trim(str) {
//    var strnew = str.replace(/^\s*|\s*$/g, "");
//    return strnew;
//}
//用户名
//function check(){
//    var xhr;
//    var readerName = document.getElementById("readerName").value;
//    if (readerName == "" || !isNaN(readerName.charAt(0))) {
//        document.getElementById("readerNameTip").innerHTML = "<font color='red'>× 首字母不能为数字或者用户名不能为空</font>";
//        return false;
//    } else if (readerName.length < 6 || readerName.length > 30) {
//        document.getElementById("readerNameTip").innerHTML = "<font color='red'>× 用户名长度为6-30位字符</font>";
////        return false;
//        if(window.XMLHttpRequest){
//            xhr = new XMLHttpRequest();
//        }
//        else {
//            xhr = new ActiveXObject("MicroSoft.XMLHTTP");//老版本的ie
//        }
//        xhr.open("get","http://localhost:8081/bookstore/reader/Reader_checkName.action?readerName="+readerName,true);
//        xhr.send();
//        xhr.onreadystatechange=function(data){
//            if(xhr.readyState==4 && xhr.status==200){
//                //var ss = xmlHttp.responseText;
//                if(data == "success"){
//                    document.getElementById("readerNameTip").html("<font color='red'>× 该用户名已经被注册，请重新输入</font>");
//                }
//            }
//        };
//    }
//};

$(document).ready(function(){
	$("#readerName").blur(function(){
		var readerName = $("#readerName").val();
		document.getElementById("readerNameTip").innerHTML = "<font color='#339933'>√ 用户名合格</font>";
		$.post("${basePath}reader/Reader_checkReaderName.action",
		  {readerName:readerName},
		  function(data){
		    if(data == "success"){
			  document.getElementById("readerNameTip").innerHTML = "<font color='red'>× 该用户名已经被注册，请重新输入</font>";
              $("#submit").attr("disabled",true);
		    }
//              for(var propName in data){
//                  $("#tip").append("<font color='red'" + propName + "--->" + data[propName] + "</font>");
//              }
	    });
	});
});

</script>

</head>
<body>

	<s:form name="readerForm" action="reader/Reader_saveReader"
		method="post">
		<input type="hidden" name="reader.id" value="${reader.id}">
		读者姓名:
		<input type="text" name="reader.name" id="readerName"
			value="${reader.name}"/>
		<span id="readerNameTip"> <s:fielderror>
				<s:param>readerName</s:param>
			</s:fielderror>
		</span>
		<br>
		读者电话:
		<input type="text" name="reader.phone" value="${reader.phone}" />
		<br>
		读者类型:
		<select name="reader.readerType.id">
			<option value="-1">全部</option>
			<c:forEach var="type" items="${readerTypes}">
				<c:choose>
					<c:when test="${type.id == reader.readerType.id }">
						<option value="${type.id}" selected="selected">${type.name}</option>
					</c:when>
					<c:otherwise>
						<option value="${type.id}">${type.name }</option>
					</c:otherwise>
				</c:choose>
			</c:forEach>
		</select>
		<s:submit id="submit" value="保存" />
	</s:form>
<span id="tip"></span>
</body>
</html>
